<?php

namespace app\api\controller;

use app\admin\model\PostersRecord;
use app\common\controller\Api;
use think\Hook;

class Posters extends Api
{

    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = [];

    /**
     * 敷衍抖音创建小程序 --- 海报列表
     * */
    public function list()
    {

        $data = \app\admin\model\Posters
            ::where('operate_id','1')
            ->where('status',1)
            ->field(['id','title'])
            ->select();

         $this->success('success',$data);
    }

    /**
     * 敷衍抖音创建小程序 --- 海报详情
     * */
    public function detail()
    {
        if (
            !($id = $this->request->get('id/d'))
            || !($record = (new PostersRecord)->with('posters')->find($id))
            || !$record->posters
        ) {
            $this->error("海报不存在");
        }

        $params = (new \addons\posters\controller\Index())->getParams($record->params);

        $content = [
            'id'     => $record->posters->id,
            'params' => $params,
            'output' => true,
            'size'   => $record->size,
        ];

        try{
            Hook::listen('posters', $content, null, true);
            throw new \Exception();
        } catch (\Exception $e){
            $this->error("海报生成失败");
        }
    }

}